class SegmentTree:
    def __init__(self, n):
        self.n = n
        self.info = [[0, 0] for _ in range(n << 2)]

    def _up(self, root):
        self.info[root][0] = self.info[root << 1][0] + self.info[root << 1 | 1][0]
        self.info[root][1] = self.info[root << 1][1] + self.info[root << 1 | 1][1]

    def settle(self, L, R):
        def f(l, r, root):
            if r < L or R < l: return
            if l == r:
                self.info[root][0] += l == L
                self.info[root][1] += l == R
            else:
                mid = (l + r) >> 1
                f(l, mid, root << 1)
                f(mid + 1, r, root << 1 | 1)
                self._up(root)

        f(1, self.n, 1)

    def query(self, L, R):
        def f(l, r, root):
            if r < L or R < l: return [0, 0]
            if L <= l and r <= R:
                return self.info[root]
            mid = (l + r) >> 1
            linfo = f(l, mid, root << 1)
            rinfo = f(mid + 1, r, root << 1 | 1)
            return [linfo[0] + rinfo[0], linfo[1] + rinfo[1]]
        return f(1, self.n, 1)

    def query2(self, L, R):
        all = self.query(1, R)
        prev = self.query(1, L-1)
        return all[0] - prev[1]


import sys
n, m = map(int, sys.stdin.readline().split())
tree = SegmentTree(n)
res = []
for line in sys.stdin.readlines():
    ops = list(map(int, line.split()))
    if ops[0] == 1:
        tree.settle(ops[1], ops[2])
    else:
        res.append(str(tree.query2(ops[1], ops[2])))
sys.stdout.write('\n'.join(res))
